package hu.ikti.oamadmin.beans.repository;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import hu.ikti.oamadmin.beans.BaseBean;
import hu.ikti.oamadmin.types.entities.Repository;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Factory;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Out;

@Name("repositoryBean")
@Scope(ScopeType.SESSION)
public class RepositoryBean extends BaseBean implements Serializable {

	private static final long serialVersionUID = 1L;

	@Out(required = false, scope = ScopeType.SESSION)
	private List<Repository> repositoryList;

	@Factory("repositoryList")
	public void getRepositoryList() {
		List<?> results = entityManager.createQuery(
				"select repository from Repository repository").getResultList();
		if (results != null) {
			repositoryList = new ArrayList<Repository>();
			for (Object object : results) {
				repositoryList.add((Repository) object);
			}
		} else {
			repositoryList = null;
		}
	}

}
